#include <iostream>
#include <climits>
#include <functional>
#include <tuple>

using namespace std;

void print_pack(std::tuple<std::string&&, int &&> pack)
{
    std::cout << get<0>(pack) << ", " << std::get<1>(pack) << "\n";
}

int main()
{
    auto f1 = [](int a) -> int {return a;};
    std::cout << f1(1)  << std::endl;

    int a = 0;
    auto f = [=]{return a;};

    a += 1;

    std::cout << f()  << std::endl;


    std::function<int(int)> f2 = [](int a){return a;};
    std::function<int(void)> f3 = std::bind([](int a) { return a; }, 123);

    typedef void (*Ptr)(int *);
    Ptr p = [](int *p){delete p;};
    Ptr p1 = [](int *p){};

    {

        std::tuple<const char * , int> tp = std::make_tuple("1111", 12); //构建一个tuple ，tuple 在std 命名空间中
    }

    {
        auto tp = std::tie(a, "aa", a); //tie 中 int 需要传入引用 //会创建一个元组的左值引用
        const char * data = std::get<1>(tp);
        cout << data << endl;

        int x, y;
        string a;
        //std::tie(x, a, y) = tp;
        cout << x  << " "<< y << " "<< a << endl;

        std::tie(std::ignore, std::ignore, y) = tp; //只解第 3 个值
        cout << x  << " "<< y << " "<< a << endl;

        string str("John");
        print_pack(std::forward_as_tuple(str + "Smith", 25)); //具有对 args 的右值引用的元组对象，适合作为参数转发给函数。
        print_pack(std::forward_as_tuple(str + "Daniels", 22));


        std::tuple<float , string> mytuple (3.14, "pi");
        std::pair<int, char> mypair(10, 'a');

        auto myauto = std::tuple_cat(mytuple, std::tuple<int, char>(mypair));
        cout << "myauto contains: " << "\n";

        std::cout << std::get<0>(myauto) << "\n";
        std::cout << std::get<1>(myauto) << "\n"; //<index> 必须传入const int 
        std::cout << std::get<2>(myauto) << "\n";
        std::cout << std::get<3>(myauto) << "\n";
    }
    return 0;
}
